package com.nwork.cateye.utils;

import android.text.TextUtils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * Created by Administrator on 2015/3/25.
 */
public class CommonUtils {
    /**
     * 将inputStream转换成String
     *
     * @param inputStream
     * @return
     */
    public static String inputToString(InputStream inputStream) {
        String ret = null;
        BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
        StringBuilder sb = new StringBuilder();
        String line = null;
        try {
            while ((line = br.readLine()) != null) {
                sb.append(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                inputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        ret = sb.toString();
        return ret;
    }

    /**
     * 将从JSON中得到的字符串解析成可以得到图片的String
     *
     * @param url
     * @return
     */
    public static String getImageUrl(String url) {
        String ret = null;
        if (!TextUtils.isEmpty(url)) {
            String[] split = url.split("movie/");
            ret = "http://p0.meituan.net/240.332/movie/" + split[1] + ".webp";
        }
        return ret;
    }
}
